package com.mindbook.vip.gawxchatinfo.controller.nostrum;

import com.mindbook.vip.gawxchatinfo.entity.nostrum.NostrumFunction;
import com.mindbook.vip.gawxchatinfo.service.nostrum.NostrumFunctionService;
import com.mindbook.vip.gawxchatinfo.utils.crud.CrudUtils;
import com.mindbook.vip.gawxchatinfo.utils.result.Result;
import com.mindbook.vip.gawxchatinfo.utils.result.ResultEnum;
import com.mindbook.vip.gawxchatinfo.utils.result.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "秘芳功能")
@RestController
@RequestMapping("nostrum/function")
public class NostrumFunctionController {

    @Autowired private NostrumFunctionService nostrumFunctionService;

    @ApiOperation(value = "新增")
    @PostMapping("/")
    public Result add(NostrumFunction nostrumFunction){
        Integer add = nostrumFunctionService.add(nostrumFunction);

        CrudUtils.validateAddResult(add);

        return ResultUtils.genSuccessResult(ResultEnum.DATA_ADD_SUCCESS.getMsg());
    }

    @PutMapping("/")
    @ApiOperation(value = "修改")
    public Result update(NostrumFunction nostrumFunction){
        Integer put = nostrumFunctionService.put(nostrumFunction);

        CrudUtils.validateUpdateResult(put);

        return ResultUtils.genSuccessResult(ResultEnum.DATA_UPDATE_SUCCESS.getMsg());
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    public Result delete(@PathVariable Integer id){
        Integer integer = nostrumFunctionService.removeByPrimaryKey(id);

        CrudUtils.validateDeleteResult(integer);

        return ResultUtils.genSuccessResult(ResultEnum.DATA_DELETE_SUCCESS.getMsg());
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询列表")
    public Result findByList(){
        List<NostrumFunction> all = nostrumFunctionService.findAll();

        return ResultUtils.genSuccessResult(all);
    }

}
